import 'package:demo/pages/pages.dart';
import 'package:get/get.dart';

class RouteNames {
  static const home = '/home';
  static const second = '/second';
}

final List<GetPage> staticRoutes = [
  GetPage(
    name: RouteNames.home,
    page: () => HomePage(),
    binding: BindingsBuilder(() => Get.lazyPut(() => HomeController())),
  ),
  GetPage(
    name: RouteNames.second,
    page: () => SecondPage(),
    binding: BindingsBuilder(() => Get.lazyPut(() => SecondController())),
  ),
];

class AppRoute {
  //
  static Future<T?>? push<T>(
    String page, {
    dynamic arguments,
    bool showDialogWhenInWeb = false,
    bool preventDuplicates = true,
  }) {
    return Get.toNamed(
      page,
      arguments: arguments,
      preventDuplicates: preventDuplicates,
    );
  }

  /// push then pop last page
  static Future<T?>? pushAndPop<T>(
    String page, {
    dynamic arguments,
  }) {
    return Get.offAndToNamed(page);
  }

  /// pop all widget to page
  static popAll<T>({String? page}) {
    //todo yue find first page
    Get.until((route) => Get.currentRoute == (page ?? RouteNames.home));
  }

  /// back to last widget
  static pop<T>({
    T? result,
    bool closeOverlays = false,
    bool canPop = true,
    int? id,
  }) {
    Get.back(
      result: result,
      closeOverlays: closeOverlays,
      canPop: canPop,
      id: id,
    );
  }

  static changeBottomBarIndex(
    int index, {
    dynamic arguments,
  }) {}
}
